package com.liujiaqi.mapper;

import com.liujiaqi.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
  // 根据ID删除数据
  @Delete("delete from emp where id = #{id}")
  public int delete(Integer id);

  // 根据username删除
  @Delete("delete from emp where username = #{username}")
  public int deleteUser(String username);

  // 新增员工操作
  @Options(keyProperty = "id", useGeneratedKeys = true) // 获取返回的主键
  @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
      " values (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
  public void insert(Emp emp);

  // 更新员工操作
  @Update("update emp set " +
      "username = #{username}, name = #{name}, gender = #{gender}, image = #{image}, job = #{job}, entrydate = #{entrydate}, dept_id = #{deptId}, update_time = #{updateTime} " +
      "where id = #{id};")
  public void update(Emp emp);

  // 根据Id查询员工
  @Select("select * from emp where id = #{id};")
  public Emp getById(Integer id);

  // 条件查询员工信息
//  @Select("select * from emp where name like concat('%', #{name}, '%') and gender = #{gender} and " +
//      "entrydate between #{begin} and #{end} order by update_time desc;")
//  public List<Emp> getList(String name, Short gender, LocalDate begin, LocalDate end);

  public List<Emp> getList(String name, Short gender, LocalDate begin, LocalDate end);

  // 动态更新员工信息
  public void update2(Emp emp);

  // 批量删除员工信息
  public void deleteByIds(List<Integer> ids);
}
